import { ElNotification, ElMessageBox } from "element-plus";
import nprogress from "nprogress";
export function msg (message,type = "success"){
    ElNotification({
        message: message,
        type: type,
        duration: 3000,
      })
}

export function showModal(content = "提示內容", type = "warning", title = "") {
  return ElMessageBox.confirm(content, title, {
    confirmButtonText: "確認",
    cancelButtonText: "取消",
    type,
  });
}

// 显示全屏loading
export function showFullLoading() {
  nprogress.start();
}

// 隐藏全屏loading
export function hideFullLoading() {
  nprogress.done();
}

// 将query对象转成url参数
export function queryParams(query){
  let q = []
  for (const key in query) {
      if(query[key]){
          q.push(`${key}=${encodeURIComponent(query[key])}`)
      }
  }
  let r = q.join("&")
  r = r ? ("&"+r) : ""
  return r
}

// sku排列算法
export function cartesianProductOf() {
  return Array.prototype.reduce.call(
    arguments,
    function (a, b) {
      var ret = [];
      a.forEach(function (a) {
        b.forEach(function (b) {
          ret.push(a.concat([b]));
        });
      });
      return ret;
    },
    [[]]
  );
}